package com.fbt.andon.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.andon.domain.FindIssue;
import com.fbt.andon.service.impl.FindIssueServiceImpl;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 产线问题Controller
 *
 * @author fengtao
 * @date 2021-08-11
 */
@RestController
@RequestMapping("/issue")
@Api(description = "问题api")
public class FindIssueController extends BaseController {
    @Autowired
    private FindIssueServiceImpl findIssueService;


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping("/query")
    @ApiOperation("查询所有问题")
    public AjaxResult findIssueList() {
        startPage();
        return AjaxResult.success("查询成功", findIssueService.list(null));
    }


    /**
     * 模糊查询问题列表
     */
//    //@PreAuthorize(hasPermi = "andon:line:list")
    @GetMapping("/list")
    @ApiOperation("根据发生区域模糊查询问题信息")
    public AjaxResult list(String area) {
        startPage();
        QueryWrapper<FindIssue> wrapper = new QueryWrapper<>();
        wrapper.like("area", area);
        return AjaxResult.success("查询成功", findIssueService.list(wrapper));
    }


    //    //@PreAuthorize(hasPermi = "andon:issue:query")
    @ApiOperation("获取产线问题详细信息，参数id")
    @GetMapping("/getIssue/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success("获取成功", findIssueService.getById(id));
    }

    /**
     * 新增产线问题
     */
//    //@PreAuthorize(hasPermi = "andon:issue:add")
    @ApiOperation("新增产线问题，参数findIssue")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FindIssue findIssue) {
        return AjaxResult.success("新增成功", findIssueService.save(findIssue));
    }

    /**
     * 修改产线问题
     */
//  //@PreAuthorize(hasPermi = "andon:issue:edit")
    @ApiOperation("根据id修改产线问题，参数findIssue")
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody FindIssue findIssue) {
        return AjaxResult.success("修改成功", findIssueService.updateById(findIssue));
    }

    /**
     * 删除产线问题
     */
//  //@PreAuthorize(hasPermi = "andon:issue:remove")
    @ApiOperation("批量删除产线问题，参数ids")
    @PostMapping("/batchRemove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success("删除成功", findIssueService.removeByIds(Arrays.asList(ids)));
    }
}
